package com.yby.mall.product.controller;

import java.util.Arrays;
import java.util.Map;

import com.yby.common.utils.PageUtils;
import com.yby.mall.product.vo.SpuInfoVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yby.mall.product.entity.SpuInfoEntity;
import com.yby.mall.product.service.SpuInfoService;
import com.yby.common.utils.R;



/**
 * spu信息
 *
 * @author yangbingying
 * @email 2771355658@qq.com
 * @date 2021-07-09 20:49:20
 */
@Api(value = "", tags = "spu信息")
@RestController
@RequestMapping("product/spuinfo")
public class SpuInfoController {
    @Autowired
    private SpuInfoService spuInfoService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(Integer page,Integer limit,Long brandId,Long catelogId,Integer status,String key){
        return spuInfoService.queryPage(page,limit,brandId,catelogId,status,key);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SpuInfoEntity spuInfo = spuInfoService.getById(id);

        return R.ok().put("spuInfo", spuInfo);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody SpuInfoVo spuInfoVo){
        return spuInfoService.saveSpuInfo(spuInfoVo);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SpuInfoEntity spuInfo){
		spuInfoService.updateById(spuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		spuInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 商品上架
     */
    @PostMapping("/{spuId}/up")
    public R spuUp(@PathVariable Long spuId){
        return spuInfoService.spuUp(spuId);
    }
}
